<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: FixPageProp.php 377 2010-09-10 08:14:28Z steen.rabol $
 *
 */

Prado::using('Application.Common.Data.PortalPageRecord');

class FixPageProp extends PortalAdminPage
{
	public static function ToolMenuName()
	{
		return Prado::localize('Fix page path');
	}

	public function onLoad($param)
	{
		parent::onLoad($param);
		$fixed	= array();
		$this->setAdminPageTitle('Fix page path');
		$records = PortalPageRecord::finder()->findAll();

		if($records)
		{
			foreach($records as $record)
			{
				if(is_null($record->path))
				{
					if(!is_null($record->fullpath) && $record->name !== $record->fullpath)
					{
						$path = explode('.', $record->fullpath);
						unset($path[count($path)-1]);
						$record->path =  implode('.',$path);
						$record->save();
						$fixed[] = array('name' => Prado::localize("Path on page {0} have been fixed", array($record->name)));
					}
				}
			}
		}

		if(count($fixed) != 0)
		{
			$this->Repeater->DataSource	= $fixed;
			$this->Repeater->dataBind();
			$this->ltNoFix->Visible	= false;
			$this->ltNoFix->Enabled	= false;
		}
		else
		{
			$this->Repeater->Visible	= false;
			$this->Repeater->Enabled	= false;
			$this->ltNoFix->Visible		= true;
			$this->ltNoFix->Enabled		= true;
		}
	}
}
?>
